/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MyClass;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.LayerManager;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author HuuTai_it
 */
public class GameManagement extends GameCanvas implements Runnable {  
    
    public Control control;
    private LayerManager layerManager = new LayerManager();
    public int[][] element = new int[10][10];
    
    private Image backgroundImage = Image.createImage("/MyPicture/background.png");   
    private Background background = new Background(backgroundImage); 
    
    private Image diffImage = Image.createImage("/MyPicture/difficult.png");   
    private Difficulties difficulties = new Difficulties(diffImage);    
    
    private Image numberImage = Image.createImage("/MyPicture/number.png");   
    private Information information = new Information(numberImage);
    
    private Image vortexImage = Image.createImage("/MyPicture/vortex.png");   
    private Vortexs vortexs;
    
    private Image islandImage = Image.createImage("/MyPicture/island.png");   
    private Islands islands;
    
    private Image mainShipImage = Image.createImage("/MyPicture/mainship.png");   
    public MainShip mainShip;
    
    private EnemyManagement enemyManagement;
    
    public GameManagement(Control control) throws Exception {
        
        super(true);
        
        this.control = control;
        setFullScreenMode(true);
        
        for(int i = 0; i < 10; i++)
            for(int j = 0; j < 10; j++)
                element[i][j] = 0;      
        
        
        mainShip = new MainShip(control.g, mainShipImage);
        information.setLevel(control.level);
        information.setScores(control.scores);
        information.setLife(control.life);
        layerManager.append(information);
<<<<<<< .mine
=======
        
>>>>>>> .r42
        vortexs = new Vortexs(this, vortexImage);
<<<<<<< .mine

=======
        
        mainShip = new MainShip(this, mainShipImage);

>>>>>>> .r42
        layerManager.append(mainShip);
        
        enemyManagement = new EnemyManagement(this);
        int n = enemyManagement.vEnemy.size();
        for(int i = 0; i < n; i++)
            layerManager.append((Sprite)enemyManagement.vEnemy.elementAt(i));
                
        for(int i = 0; i < vortexs.vVortex.size(); i++)
            layerManager.append((Sprite)vortexs.vVortex.elementAt(i));
        
        islands = new Islands(this, islandImage);
        islands.setVisible(true);
        layerManager.append(islands);
        difficulties.setDiff(control.difficulties);
        difficulties.setVisible(true);
        layerManager.append(difficulties);        
        information.setLevel(control.level);
        information.setScores(control.scores);
        information.setLife(control.life);
        information.setVisible(true);
        layerManager.append(information);
        background.setVisible(true);
        layerManager.append(background);
        
    }
    
    public void start() {        
        
        Thread t = new Thread(this);
        t.start();
    }
    
    public void run() {
        
        Graphics g = getGraphics();
        
        while(true)
            drawScreen(g);
    }
    
    public void drawScreen(Graphics g) {
        
        long currTime = System.currentTimeMillis();
        vortexs.turn(currTime);

        mainShip.wobble(currTime);
        enemyManagement.wobble(currTime);
        flushGraphics();
    }
    
    public void keyPressed(int keyCode) {
    }
    
}
